<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>字符串测试</title>
</head>

<body>
    <script>
        // 1.反转字符串
        var str = "abcdef"
        var i = str.length;
        i = i - 1;
        for (var x = i; x >= 0; x--) {
            document.write(str.charAt(x));
        }
        // 2.统计字符串中指定字符的个数
        function NumCount(assign) {
            var str = "asfesWsdA"
            var n = (str.split(assign)).length - 1;
            return n;
        }
        console.log(NumCount("s"));
        // 3.去前后空格
        let strs = "            hello world   "
        function LTrim(str) {
            var i;
            for (i = 0; i < str.length; i++) {
                if (str.charAt(i) != " ") break;
            }
            str = str.substring(i, str.length);
            return str;
        }
        console.log(LTrim(strs))
        // 创建一个长度为100的数组，并且全部填充为1
        let arrayss = new Array();
        arrayss.length = 100;
        arrayss.fill(1,0,(arrayss.length -1) + 1)
        console.log(...arrayss)
        //fill: 填充数字,起始位置,结束位置
    </script>
</body>

</html>